import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

import sun.awt.image.ImageWatched.Link;

/*
 * @Author: qianmingtian
 * @Date: 2020-06-18 10:42:31
 * @LastEditors: qianmingtian
 * @LastEditTime: 2020-06-19 09:46:47
 * @FilePath: \qianmingtian.github.io\code\java\ExceptionStack.java
 */
public class ExceptionStack {

    public static int add(final int n) {
        System.out.println("add " + n + ":");
        final Throwable t = new Throwable();
        final StackTraceElement[] frames = t.getStackTrace();
        for (final StackTraceElement st : frames)
            System.out.println(st);
        int r;
        if (n <= 1)
            r = 1;
        else
            r = n * add(n - 1);
        System.out.println("return " + r);
        return r;
    }

    public static void main(final String[] args) {
        final Scanner in = new Scanner(System.in);
        System.out.println("enter n:");
        final int n = in.nextInt();
        add(n);
        in.close();

        final LinkedList<Integer> ll = new LinkedList<Integer>();
        ll.add(1);
        ll.add(2);
        ll.remove(1);
        ll.add(1);
        ll.add(3);

        Iterator<Integer> it = ll.iterator();

        while (it.hasNext()) {
            System.out.println(it.next());
        }

        if (!ll.isEmpty()) {

            System.out.println(ll);

        }

    }
}